<template>
  <a-card style="width: 100%;">
    <div style="display: flex">
      <div>导师初始化：</div>
      <div>
        <a-checkbox
          :indeterminate="indeterminate"
          @change="onCheckAllChange"
          :checked="checkAll"
        >
          全选&nbsp;
        </a-checkbox>
        <br>
        <a-checkbox-group :options="plainOptions" v-model="checkedList" @change="onChange" />
      </div>
    </div>
    <a-row style="text-align: center"> <a-button type="primary" @click="save">保存</a-button></a-row>
  </a-card>
</template>

<script>
export default {
  data () {
    return {
      checkedList: [],
      indeterminate: true,
      checkAll: false,
      plainOptions: ['是否超龄']
    }
  },
  created () {
    this.$store.dispatch('app/sysInfo').then(sys => {
      if (sys.dssfcl == '1') {
        this.checkedList.push('是否超龄')
        this.indeterminate = false
        this.checkAll = true
      }
    })
  },
  methods: {
    onChange (checkedList) {
      this.indeterminate = !!checkedList.length && (checkedList.length < this.plainOptions.length)
      this.checkAll = checkedList.length === this.plainOptions.length
    },
    onCheckAllChange (e) {
      Object.assign(this, {
        checkedList: e.target.checked ? this.plainOptions : [],
        indeterminate: false,
        checkAll: e.target.checked
      })
    },
    save () {
      let sfcl = this.checkedList.includes('是否超龄') ? 1 : 0
      this.$api.teacher.teacherIsOverAge({sfcl}).then(res => {
        this.$message.success(res.msg)
      })
    }
  }
}
</script>

<style>

</style>
